package treeNode;

public class Solution8 {
    public boolean hasPathSum(TreeNode root, int sum) {
        if(root==null){
            return false;
        }
        if(root.left==null&&root.right==null){
            return sum == root.val;
        }

        return hasPathSum(root.left,sum-root.val)||hasPathSum(root.right,sum-root.val);


    }

    public static void main(String[] args) {
        TreeNode treeNode =TreeNodeUtils.getTestTreeNode();
        System.out.println(new Solution8().hasPathSum(treeNode,8));
        System.out.println(new Solution8().hasPathSum(treeNode,17));
        System.out.println(new Solution8().hasPathSum(treeNode,100));
    }

}
